﻿namespace BM.Tools.WebControls.MForm.ScriptReferences
{
    using System.Text;
    using System.Web.UI;

    /// <summary>
    /// A commponenent descriptor that can use jquery query to define the component node.
    /// </summary>
    public class JQueryComponentDescriptor : ScriptComponentDescriptor
    {
        private string selector;

        /// <summary>
        /// Initializes a new instance of the <see cref="JQueryComponentDescriptor"/> class. 
        /// </summary>
        /// <param name="type">
        /// The client-side object type.
        /// </param>
        /// <param name="selector">
        /// The jquery selector.
        /// </param>
        public JQueryComponentDescriptor(string type, string selector) : base(type)
        {
            this.selector = selector;
        }

        /// <summary>
        /// returns the script of the descriptor
        /// </summary>
        /// <returns>
        /// the script of the descriptor
        /// </returns>
        protected override string GetScript()
        {
            var builder = new StringBuilder(base.GetScript());
            builder.Remove(builder.Length - 2, 2);
            builder.Append(", ");
            builder.Append(selector);
            builder.Append(");");
            return builder.ToString();
        }
    }
}